﻿using Inaction;
using Inaction.Core;
using Inaction.Criteria;
using Inaction.Mapping;
using Inaction.Security;
using Inaction.ServiceProxy;
using System;
using System.Security.Principal;

namespace Inaction
{
    public static class Proxy
    {
        #region 属性

        static IProxy instance = new LocalProxy();
        public static IProxy Instance
        {
            get { return instance; }
            set { instance = value; }
        }
        #endregion

        #region Proxy
        public static void Login(string userNumber, string password)
        {
            Principal.Instance = new DefaultPrincipal(userNumber, password);
            Instance.Login();
        }
        public static object Query(Type type, CriteriaBase criteria, Type itemType
#if !PocketPC
            = null
#endif
            )
        {
            if (itemType == null)
            {
                return Instance.Query(type, SqlStatement.GetSelectStatement(type, criteria));
            }
            else
            {
                return Instance.Query(type, SqlStatement.GetSelectStatement(itemType, criteria));
            }
        }
#if PocketPC
        public static object Query(Type type, CriteriaBase criteria)
        {
            return Instance.Query(type, SqlStatement.GetSelectStatement(type, criteria));
        }
#endif
        public static object Query(Type entityType, SqlStatement sql)
        {
            return Instance.Query(entityType, sql);
        }
        public static T Query<T>(EntitySqlStatement sql)
        {
            return (T)Instance.Query(typeof(T), sql);
        }

        public static object Save(ISavable obj)
        {
            return Instance.Save(obj);
        }
        public static object Excute(SqlCommand command)
        {
            return Instance.Excute(command);
        }
        public static object Invoke(RemotingMethod method)
        {
            return Instance.Invoke(method);
        }
        #endregion
    }
}